﻿using ProjectFootball.MVC.Models.EntityFramework.Entities;
using System;
using System.Security.Principal;

namespace ProjectFootball.MVC.Areas.MatchArea.Models
{
    public static class _MatchEventDataModelExtensions
    {
        public static MatchEvent _CreateNew(this MatchEventDataModel matchEventDataModel, IPrincipal user)
        {
            matchEventDataModel.ApprovalGuid = Guid.NewGuid();

            return matchEventDataModel._CreateUnapproved(user);
        }

        public static MatchEvent _CreateUnapproved(this MatchEventDataModel matchEventDataModel, IPrincipal user)
        {
            return new MatchEvent()
            {
                Pk = Guid.NewGuid(),
                ApprovalGuid = matchEventDataModel.ApprovalGuid,
                MatchGuid = matchEventDataModel.MatchGuid,
                TeamGuid = matchEventDataModel.TeamGuid,
                PersonGuid = matchEventDataModel.PersonGuid,
                MatchEventType = matchEventDataModel.MatchEventType,
                Minute = matchEventDataModel.Minute,
                Extra = matchEventDataModel.Extra,
                IsApproved = user.IsApprover(),
                AuditUserId = user.GetUserId(),
                AuditTimestamp = DateTime.Now
            };
        }
    }
}